package com.fay.basic.base.string;

import lombok.Data;

/**
 * @Title:
 * @Description:
 * @Author Fay Wang
 * @Date 2022/5/10 16:17
 * @Version 1.0
 */
public class StringTest {
    public static void main(String[] args) {
//        checkStringAsArgs();
        checkStringAsObjectProperties();
    }

    /**
     * 对象含有String作为方法参数传递
     */
    private static void checkStringAsObjectProperties() {
        StringObject so = new StringObject();
        so.setName("123");
        User user = new User();
        user.setName("Fay");
        so.setUser(user);
        so.setAge(12);
        changeObjectStr(so);
        StringObject so2 = changeObjectStr(so);
        System.out.println(so.getName()+so.getUser()+so.getAge());
        System.out.println(so2.getName()+so2.getUser()+so2.getAge());
    }

    private static StringObject changeObjectStr(StringObject so) {
        so = new StringObject();
        User user = new User();
        user.setName("Jack");
        so.setUser(user);
        so.setName("456");
        so.setAge(88);
        return so;
    }

    /**
     * String作为方法参数传递，是“值传递”，
     * 即方法操作的是参数变量（也就是原型变量的一个值的拷贝）
     */
    private static void checkStringAsArgs() {
        String str = "123";
        changeStr(str);
        System.out.println(str);
    }

    private static void changeStr(String str) {
        str = "456";
    }

}

@Data
class StringObject {
    String name;
    User user;
    Integer age;
}
@Data
class User {
    String name;
}
